﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;//ERP.Classes
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_loaihopdongInfo
    {
        private string _maloai;
        private string _tenloai;
        private string _ghichu;

        public cs_hmr_loaihopdongInfo(string maloai, string tenloai, string ghichu)
        {
            this._maloai = maloai;
            this._tenloai = tenloai;
            this._ghichu = ghichu;

        }
        public cs_hmr_loaihopdongInfo()
        {
            this._maloai = " ";
            this._tenloai = " ";
            this._ghichu = " ";

        }
        public string maloai
        {
            get
            {
                return this._maloai;
            }
            set
            {
                this._maloai = value;
            }
        }
        public string tenloai
        {
            get
            {
                return this._tenloai;
            }
            set
            {
                this._tenloai = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@maloai";
            paraName[1] = "@tenloai";
            paraName[2] = "@ghichu";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._maloai;
            paraValue[1] = this._tenloai;
            paraValue[2] = this._ghichu;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[3];
            fields[0] = "maloai";
            fields[1] = "tenloai";
            fields[2] = "ghichu";
            list.KetDulieu(myList, "HMR_LOAIHOPDONG", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_LOAIHOPDONG", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tenloai", "maloai");
            cb.KetDuLieu(cbo, "HMR_LOAIHOPDONG", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[3];
            header[0] = "maloai";
            header[1] = "tenloai";
            header[2] = "ghichu";

            string[] mappingname = new string[3];
            mappingname[0] = "maloai";
            mappingname[1] = "tenloai";
            mappingname[2] = "ghichu";

            int[] colwidth = new int[3];
            colwidth[0] = 30;
            colwidth[1] = 360;
            colwidth[2] = 360;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_LOAIHOPDONG", datagrid, csdl.OpenTable("HMR_LOAIHOPDONG", condition), header, mappingname, colwidth, 3);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_LOAIHOPDONG", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._maloai = ds.Tables[0].Rows[0]["maloai"].ToString().Trim();
                this._tenloai = ds.Tables[0].Rows[0]["tenloai"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select rtrim(maloai) as maloai, rtrim(tenloai) as tenloai"
                        + " from hmr_loaihopdong";
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
